package com.acwing.lc.part1;

/**
 * @author rkc
 * @date 2022/9/16 16:41
 */
public class LC63不同路径II {

    public int uniquePathsWithObstacles(int[][] g) {
        int n = g.length, m = g[0].length;
        int[][] f = new int[n + 10][m + 10];
        for (int i = 0; i < n && g[i][0] != 1; i++) f[i][0] = 1;
        for (int j = 0; j < m && g[0][j] != 1; j++) f[0][j] = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                if (g[i][j] != 1) {
                    f[i][j] = f[i - 1][j] + f[i][j - 1];
                }
            }
        }
        return f[n - 1][m - 1];
    }
}
